//
//  NSDate+MMAdd.m
//  EraPig
//
//  Created by Mac_Mini on 2021/3/22.
//

#import "NSDate+MMAdd.h"

@implementation NSDate (MMAdd)

/// 获取今天的日期不含时分秒 2020-02-02
+ (NSString *)getTodayDateString{
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    formatter.dateFormat = @"yyyy-MM-dd";
    return [formatter stringFromDate:[NSDate date]];
}

/// 获取明天的日期 2020-02-02 02:02:02 -> 2020-02-03 02:02:02
- (NSDate *)getTomorrowDate{
    NSCalendar *calendar = [[NSCalendar alloc]initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
    NSDateComponents *components = [calendar components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay|NSCalendarUnitHour|NSCalendarUnitMinute|NSCalendarUnitSecond fromDate:self];
    [components setDay:[components day]+1];
    return [calendar dateFromComponents:components];
}

/// date转字符串
- (NSString *)toStringByFormatter:(NSString *)aFormatter{
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    formatter.dateFormat = aFormatter;
    return [formatter stringFromDate:self];
}
@end
